package com.sky.controller.user;

import com.sky.constant.StatusConstant;
import com.sky.entity.Dish;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "菜品相关接口")
@RequestMapping("/user/dish")
@RestController("userDishController")
@Slf4j
public class DishController {

    @Autowired
    private DishService dishService;

    /**
     * 根据分类id查询菜品
     * @param categoryId 分类id
     * @return 菜品列表
     */
    @ApiOperation(value = "根据分类id查询菜品")
    @ApiImplicitParam(name = "categoryId", value = "分类id", required = true, example = "1", paramType = "query", dataType = "long")
    @GetMapping("/list")
    public Result<List<DishVO>> getDishListByCategoryId(@RequestParam Long categoryId) {
        Dish dish = new Dish();
        dish.setCategoryId(categoryId);
        dish.setStatus(StatusConstant.ENABLE); // 查询起售中的菜品
        List<DishVO> dishList = dishService.getDishListWithFlavor(dish);
        return Result.success(dishList);
    }

}
